
import {Iaction} from '../../utils/interface';
import {setCookie} from '../../utils/cookie';
const initialState={
    mobile:'',
    isLogin:false,
    collectList:[],
    userInfo:{}
}
const actions:{[key:string]:Function}={
    'INIT_USER':(state:any,action:Iaction)=>{
        setCookie(action.payload.sessionKey)
        state = Object.assign(state,{mobile:action.payload.mobile,isLogin:true})
    },
    'INIT_INFO':(state:any,action:Iaction)=>{
        state = Object.assign(state,{userInfo:action.payload})
    },
    'UPDATE_INFO':(state:any,action:Iaction)=>{
        alert(action.payload.msg)
    },
    'INIT_COLLECT':(state:any,action:Iaction)=>{
        state = Object.assign(state,{collectList:action.payload})
    },
    'DEL_COLLECT':(state:any,action:Iaction)=>{
        // state = Object.assign(state,{collectList:action.payload})
    },
}
const reducer = (state=initialState,action:Iaction)=>{
    const newState = JSON.parse(JSON.stringify(state));
    actions[action.type] && actions[action.type](newState,action);
    return newState
}

export default reducer